<template>
  <div>Home</div>

  <!-- 添加按钮 -->
  <div>
    <input type="text" v-model="inputdata"/>
    <button @click="fetchData">获取数据</button>
  </div>

  <p>{{ data }}</p>

</template>

<script>
import { getTest } from "../api/getData.js";

export default {
  data() {
    return {
      data: '',
      inputdata:' ',
    }
  },

  methods: {
    // 定义获取数据的方法
    fetchData() {
      getTest(this.inputdata)
          .then(response => {
            this.data = response.data.message;
          })
          .catch(error => {
            console.error("请求失败：", error);
            this.data = '请求失败:'+this.inputdata;
          });
    },
  },
}
</script>

<style scoped>

</style>
